#ifndef MQTT_CLIENT_H
#define MQTT_CLIENT_H

#include "mqtt_client.h"
#include "DeviceManager/DeviceManagerDefine.h"

typedef struct MqttClient MqttClient;

// ---------------- 回调类型 ----------------
//---mqtt--连接
typedef void (*mqtt_connect_callback_t)(MqttClient *manager, esp_event_base_t event_base, int32_t event_id);
//---收到发送的数据
typedef void (*mqtt_recv_msg_callback_t)(MqttClient *manager, MessageType messageType, void *data);

///初始化 并设置连接回调 接收消息回调
MqttClient *mqtt_client_init(mqtt_connect_callback_t connect_callback, mqtt_recv_msg_callback_t recv_msg_callback);

///支持重新设置连接回调
void MqttClient_set_connect_callback(MqttClient *handle, mqtt_connect_callback_t cb);

///支持重新接收消息回调
void MqttClient_set_recv_msg_callback(MqttClient *handle, mqtt_recv_msg_callback_t cb);

///启动mqtt
void mqtt_client_start(MqttClient *handle, const char *mqttHost, const char *user_name, const char *password, int mqttPort,  const char *topic);
///停止mqtt
void mqtt_client_stop(MqttClient *handle);

// 检查是否需要连接 MQTT 服务器
bool mqtt_connect_if_needed(MqttClient *handle, const char *mqttHost, int mqttPort);

// 销毁句柄
void destroy_mqtt(MqttClient *handle);

/// 内部访问
static void mqtt_client_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data);
#endif // MQTT_CLIENT_H
